<template>
  <div class="crumb">
    <el-breadcrumb separator-icon="ArrowRight">
      <template v-for="(item, index) in breadList" :key="index">
        <el-breadcrumb-item :to="item.path">{{ item.name }}</el-breadcrumb-item>
      </template>
    </el-breadcrumb>
  </div>
</template>

<script setup lang="ts">
import { ref, watch } from 'vue'
import { useRoute } from 'vue-router'
import { useLoginStore } from '@/store/login/login'
import { mapRouteToBread } from '@/utils/map-menus'
const route = useRoute()
const userMenuList = useLoginStore().userMenus
const breadList = ref([])

// 当页面的路径发生变化的时候，要重新查询面包屑
watch(
  () => route.path,
  (newVal) => {
    breadList.value = mapRouteToBread(newVal, userMenuList)
  },
  {
    immediate: true,
  },
)
</script>

<style scoped lang="less">
.crumb {
  color: red;
}
</style>
